package org.nio;

import java.nio.ByteBuffer;

/**
 * @author wind
 * @create 2025-01-07 11:26
 */
public class BufferSplitDemo {
    public static void main(String[] args) {
        String str = "hello,wind,#i am feng,#could you give# me a hand?#";
        ByteBuffer source = ByteBuffer.allocate(51);
        source.put(str.getBytes());
        source.flip();
        for(int i=0;i<source.limit();i++){
            if(source.get(i)=='#'){
                int len = i-source.position() +1;
                System.out.println("len: "+len);
                ByteBuffer target = ByteBuffer.allocate(len);
                source.limit(i + 1);
                target.put(source);
                ByteBufferUtil.debug(target);
                //source.limit(len);
            }
        }
        source.compact();
    }
}
